package com.tianbing.adlottery.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.fengniu.ejb.business.ISiteBusiness;
import com.fengniu.ejb.dao.ISiteDao;
import com.fengniu.ejb.entity.Category;
import com.fengniu.ejb.entity.Site;
import com.fengniu.ejb.entity.Site2Category;

/**
 * MultiActionController for the image list/upload UI.
 * 
 * @author Conan Chen
 * @since 2006.12.15
 */
public class WebSiteController extends MultiActionController {
	Logger logger = Logger.getLogger(WebSiteController.class.getName());

	private String webSiteDetailView;

	private String webSiteDetailBannerView;

	private String ajaxListHotWebSiteView;

	private ISiteDao siteDao;

	private ISiteBusiness siteBusiness;

	public ModelAndView ajaxListHotWebSite(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Category siteCategory = null;
		ModelAndView mv = new ModelAndView(ajaxListHotWebSiteView);
		Map model = mv.getModel();

		// get site store detail
		String sgid = ServletRequestUtils.getStringParameter(request, "sgid", null);
		if (sgid != null) {
			int pgno = 0;
			int pgsize = 500;
			Map s2gMap = siteBusiness.getHotWebSites(sgid, pgno, pgsize);
			List<Site2Category> s2cList = (List<Site2Category>) s2gMap.get("site2CategoryList");
			model.put("site2CategoryList", s2cList);
		}
		return mv;
	}

	public ModelAndView viewWebSiteDetail(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Category siteCategory = null;
		List primarySiteCategoryTrail = null;
		ModelAndView mv = new ModelAndView(webSiteDetailView);
		Map model = mv.getModel();

		// get site store detail
		Long ssid = ServletRequestUtils.getLongParameter(request, "ssid", -1);
		Site siteDetail = siteDao.findSiteBySysId(ssid);

		model.put("siteDetail", siteDetail);

		return mv;
	}

	public ModelAndView viewWebSiteDetailBanner(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Category siteCategory = null;
		List primarySiteCategoryTrail = null;
		ModelAndView mv = new ModelAndView(webSiteDetailBannerView);
		Map model = mv.getModel();

		// get site store detail
		Long ssid = ServletRequestUtils.getLongParameter(request, "ssid", -1);
		Site siteDetail = siteDao.findSiteBySysId(ssid);

		model.put("siteDetail", siteDetail);

		return mv;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public void setWebSiteDetailView(String webSiteDetailView) {
		this.webSiteDetailView = webSiteDetailView;
	}

	public void setWebSiteDetailBannerView(String webSiteDetailBannerView) {
		this.webSiteDetailBannerView = webSiteDetailBannerView;
	}

	public void setSiteDao(ISiteDao siteDao) {
		this.siteDao = siteDao;
	}

	public void setAjaxListHotWebSiteView(String ajaxListHotWebSiteView) {
		this.ajaxListHotWebSiteView = ajaxListHotWebSiteView;
	}

	public void setSiteBusiness(ISiteBusiness siteBusiness) {
		this.siteBusiness = siteBusiness;
	}

}
